﻿// <copyright file="SecurityDescriptorContainer.cs" company="Sinclair Community College">
// Copyright 2010 Sinclair Community College
// </copyright>
// <originalAuthor>Patrick S. Seymour (patrick.seymour@gmail.com)</originalAuthor>

namespace SinclairCC.AppV
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// This container points to an inline security descriptor table or a set of StorageBlockInfo
    /// structures which point to the storage blocks which contain the security descriptor table.
    /// </summary>
    /// <remarks>
    /// This container has no Data Information Region so the InfoDataLength value in the header
    /// will be set to zero (0).
    /// </remarks>
    public class SecurityDescriptorContainer : Container
    {
        private StorageBlockInfoTable storageBlockTable;

        /// <summary>
        /// Initializes a new instance of the SecurityDescriptorContainer class.
        /// </summary>
        public SecurityDescriptorContainer(System.IO.BinaryReader fileReader)
            : base(fileReader)
        {
            this.storageBlockTable = null;
            this.ReadContainer(fileReader);
        }

        /// <summary>
        /// Reads the actual data for this container from the file.
        /// </summary>
        protected void ReadContainer(System.IO.BinaryReader fileReader)
        {
            // If DataStorageType is true for FORMAT_BLOCKMAP flag, then right after the common header,
            // there can be one or more StorageBlockInfo structures which point to the actual storage
            // blocks that contain the security descriptors. If DataStorageType is true for FORMAT_INLINE
            // flag, the security descriptors are within this container, right after the common header.
            if ((this.Header.StorageType & DataStorageType.FORMAT_BLOCKMAP) == DataStorageType.FORMAT_BLOCKMAP)
            {
                this.storageBlockTable = new StorageBlockInfoTable(fileReader);
            }
            else if ((this.Header.StorageType & DataStorageType.FORMAT_INLINE) == DataStorageType.FORMAT_INLINE)
            {
                /*
                _SECURITY_HDR header;
                do
                {
                }
                */
            }

            /*
            this.blockCount = fileReader.ReadUInt32();
            this.mapLength = fileReader.ReadUInt32();

            StorageBlockInfo stBlock;
            do
            {
                uint allocIndex = fileReader.ReadUInt32();
                uint numBlocks = fileReader.ReadUInt32();
                stBlock = new StorageBlockInfo(allocIndex, numBlocks);
            }
            while (!((stBlock.BlockCount == 0) && (stBlock.AllocationIndex == 0)));
            */
        }

        public StorageBlockInfoTable StorageBlockTable
        {
            get { return this.storageBlockTable; }
        }
    }
}
